package com.sjy.mvvmdemo.roomdb.db

import android.content.Context
import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.coroutineScope

/**
 * 测试用例，由workManager管理
 */
class DbTestDataInit(
    context: Context,
    workerParams: WorkerParameters
) : CoroutineWorker(context, workerParams) {

    override val coroutineContext = Dispatchers.IO

    override suspend fun doWork(): Result = coroutineScope {

        val database = UserDatabase.getInstance(applicationContext)

        val mList = mutableListOf<UserEntity>()

        (1..1000).forEach {
            mList.add(UserEntity(it, "user$it", "pass$it", "email$it"))
        }
        database.mUserDao.addLists(mList)
        Result.success()
    }
}